package com.ssm.pre.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ssm.pre.dao.WechatAppDao;
import com.ssm.pre.service.WechatAppService;
import com.ssm.pre.util.PageCount;
import com.ssm.pre.util.ToolUtil;
import com.ssm.util.object.InputObject;
import com.ssm.util.object.OutputObject;

@Service
public class WechatAppServiceImpl implements WechatAppService {

	@Autowired
	private WechatAppDao wechatAppDao;
	
	/**
	 * 添加微信公众号的配置信息
	 */
	@Override
	public void addWechatAppInfo(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
		map.put("createId", inputObject.getLogParams().get("id"));
		map.put("createTime", ToolUtil.getTimeAndToString());
		wechatAppDao.addWechatAppInfo(map);

	}

	/**
	 * 根据ID删除微信公众号的配置信息
	 */
	@Override
	public void deleteWechatAppById(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
		wechatAppDao.deleteWechatAppById(map);
	}

	/**
	 * 查询所有的微信公众号配置信息
	 */
	@Override
	public void queryWechatAppByList(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
		List<Map<String, Object>> beans = wechatAppDao.queryWechatAppByList(map);
		int page = Integer.parseInt(map.get("offset").toString())/Integer.parseInt(map.get("limit").toString());
		page++;
		List<Map<String, Object>> params = PageCount.page(beans, page, Integer.parseInt(map.get("limit").toString()));
		outputObject.setBeans(params);
		outputObject.settotal(beans.size()); 
	}

	/**
	 * 根据ID查询一条记录
	 */
	@Override
	public void queryWechatAppById(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
		Map<String, Object> bean = wechatAppDao.queryWechatAppById(map);
		outputObject.setBean(bean);
	}

	/**
	 * 根据ID修改一条记录
	 */
	@Override
	public void updateWechatAppById(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
		map.put("createId", inputObject.getLogParams().get("id"));
		map.put("createTime", ToolUtil.getTimeAndToString());
		wechatAppDao.updateWechatAppById(map);
	}

}
